package com.gwtgeo.ui.client.mvp.savemapas;

import java.util.Map;

import com.google.gwt.user.client.ui.HasText;
import com.gwtgeo.ui.client.mvp.adapter.HasTextFormItemAdapter;
import com.gwtgeo.ui.client.mvp.windowsmanager.WindowedDisplay;
import com.gwtgeo.ui.client.mvp.windowsmanager.WindowedView;
import com.smartgwt.client.types.HeaderControls;
import com.smartgwt.client.widgets.IButton;
import com.smartgwt.client.widgets.events.HasClickHandlers;
import com.smartgwt.client.widgets.form.DynamicForm;
import com.smartgwt.client.widgets.form.fields.TextItem;
import com.smartgwt.client.widgets.layout.HLayout;
import com.smartgwt.client.widgets.layout.VLayout;

public class SaveMapAsView extends WindowedView<VLayout> implements
		SaveMapAsPresenter.Display {

	private DynamicForm form;

	private TextItem fileNameItem;

	private IButton acceptButton;

	private IButton cancelButton;

	public SaveMapAsView() {
		super();
	}

	@Override
	public HasClickHandlers getAcceptClick() {
		return this.acceptButton;
	}

	@Override
	public HasText getFileName() {
		return new HasTextFormItemAdapter(this.fileNameItem);
	}

	@Override
	protected VLayout buildWidget() {

		VLayout widget = new VLayout();

		form = new DynamicForm();
		this.fileNameItem = new TextItem("fileName", "File name");
		this.fileNameItem.setRequired(true);
		
		form.setItems(this.fileNameItem);
		widget.addMember(form);

		HLayout buttonsPanel = new HLayout();

		acceptButton = new IButton("Accept");
		cancelButton = new IButton("Cancel");

		buttonsPanel.addMember(acceptButton);
		buttonsPanel.addMember(cancelButton);
		buttonsPanel.setMembersMargin(5);

		widget.addMember(buttonsPanel);
		
		return widget;
	}

	@Override
	protected int getWindowHeight() {
		return 100;
	}

	@Override
	protected String getWindowTitle() {
		return "Save As";
	}

	@Override
	protected int getWindowWidth() {
		return 400;
	}

	@Override
	public HasClickHandlers getCancelClick() {
		return cancelButton;
	}

	@Override
	public boolean validate() {
		return this.form.validate();
	}
	
	@Override
	protected void addHeaderControls(Map<String, HasClickHandlers> headers) {
		window.setHeaderControls(HeaderControls.HEADER_LABEL, headers
				.get(WindowedDisplay.CLOSE_HEADER));
	}

}
